import { useCookies } from 'vue3-cookies'

const { cookies } = useCookies()

const header = 'token'

const tokenPrefix = 'Bearer '

export const setCookie = (key, cookie) => {
  // 设置cookie
  cookies.set(key, cookie, '1d')
}

export const getCookie = (key) => {
  // 获取cookie
  return cookies.get(key)
}

export const removeCookie = (key) => {
  // 删除指定key
  cookies.remove(key)
}

export const setToken = (token) => {
  // 设置cookie
  cookies.set(header, tokenPrefix + token, '12h')
}

export const getToken = () => {
  // 获取cookie
  return cookies.get(header)
}

export const removeToken = () => {
  // 删除指定key
  cookies.remove(header)
}
